import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;

public class MyJDBC {


    public static void main(String[] args) throws SQLException {


        MysqlDataSource dataSource=new MysqlDataSource();
        dataSource.setURL("jdbc:mysql://127.0.0.1:3306/mycnblog?characterEncoding=utf8&&useSSL=false&&serverTimezone=Asia/Shanghai");
        dataSource.setUser("debian-sys-maint");
        dataSource.setPassword("Km2tkE3lgCd3ciF0");

         try(Connection connection=dataSource.getConnection()){

             String sql="show tables";
             try(PreparedStatement preparedStatement=connection.prepareStatement(sql)){

                 try(ResultSet resultSet=preparedStatement.executeQuery()){

                     while(resultSet.next()){
                         String tableName=resultSet.getString(1);
                         System.out.println(tableName);
                     }
                 }
             }
         }
    }
}
